#!/bin/bash
########################################################################
# (C) Copyright 2008 Muhammed Uluyol
########################################################################
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
########################################################################
#
# This script generates html files from the database

[ -f lib_helper.cfg ] || echo "CANT FIND CONFIG"
source lib_helper.cfg

for bk in `sed 's| |SpAcE|' <$DB_NAME.bkdb`; do
	CODE=$(echo $bk | sed 's/.*SpAcE//')
	bk=$DB_DIR/`echo $bk | sed 's/SpAcE.*//'`
	echo "* Converting `basename $bk`"
	sed \
		-e s_@@TITLE@@_"`cat $bk | grep 'TITLE: ' | sed 's|TITLE: ||'`"_ \
		-e s_@@AUTHOR@@_"`cat $bk | grep 'AUTHOR: ' | sed 's|AUTHOR: ||'`"_ \
		-e s_@@SUMMARY@@_"`cat $bk | grep 'SUMMARY: ' | sed 's|SUMMARY: ||'`"_ \
		-e s_@@TAGS@@_"`cat $bk | grep 'TAGS: ' | sed 's|TAGS: ||'`"_ \
		-e s_@@CODE@@_"$CODE"_ \
		<$HTML_TEMPLATE >$HTML_DIR/`basename $bk | sed 's|.bk||g'`.html
done
